import tkinter as tk
from tkinter import ttk
import json

class TestingFrame:
    def __init__(self, testing_frame, language_switcher=None, config_manager=None):
        self.Testing_frame = testing_frame
        self.language_switcher = language_switcher
        self.config_manager = config_manager  # 接收 ConfigManager 实例
        self.config = self.config_manager.get_config()  # 获取配置

        # 创建所有Entry控件
        self.create_widgets()

        if self.language_switcher:
            self.language_switcher.lang_manager.register_callback(self.update_texts)

        # 配置样式
        self.configure_styles()

    def configure_styles(self):
        style = ttk.Style()
        style.configure("TLabelFrame", font=('Arial', 12, 'bold'))
        style.configure("TLabel", font=('Arial', 12))
        style.configure("TEntry", font=('Arial', 12))
        style.configure("TCombobox", font=('Arial', 12))
        style.configure("TButton", font=('Arial', 14, 'bold'))

    def update_texts(self):
        # 更新所有控件的文本
        print("update_texts")

    def create_widgets(self):
        # 动态创建控件
        print("create_widgets")
        for i in range(4):
            area_frame = ttk.LabelFrame(self.Testing_frame, text=f"{i+1}#测试区")
            area_frame.pack(side=tk.LEFT, padx=10, pady=10, fill=tk.BOTH, expand=True)

            # 串口控制
            port_label = ttk.Label(area_frame, text=f"{i+1}#")
            port_label.grid(row=0, column=0)

            self.combo_port = ttk.Combobox(area_frame, values=[f"COM{i}" for i in range(10)])
            self.combo_port.set(f"COM2")
            self.combo_port.grid(row=0, column=1)

            self.btn_open = ttk.Button(area_frame, text="打开", command=lambda idx=i: self.toggle_port(idx))
            self.btn_open.grid(row=0, column=2)

    def toggle_port(self, idx):
        pass


 